# 作者: 家里蹲 吴越洋
# 2023年03月09日19时04分09秒
import os
from multiprocessing import Manager,Pool
from multiprocessing import Queue
import time

def write_proc(q:Queue):
    print(f'write{os.getpid()}已启动，父进程是{os.getppid()}')
    for i in range(10):
        q.put(i)
        time.sleep(1)

def read_proc(q:Queue):
    print(f'read{os.getpid()}已启动，父进程是{os.getppid()}')
    while True:
        if not q.empty():
            print(f'read{os.getpid()}读到消息{q.get()}')
            time.sleep(2)
        else:
            break

if __name__ == '__main__':
    q=Manager().Queue()
    po=Pool()
    po.apply_async(write_proc,(q,))

    time.sleep(1)

    po.apply_async(read_proc,(q,))
    po.close()
    po.join()
    print("(%s) End" % os.getpid())
